class Solution {
public:
    vector<string> topKFrequent(vector<string>& words, int k) {
        vector<string> v;
        map<string,int> m;
        for(auto e:words)
        {
            m[e]++;
        }
        multimap<int,string,greater<int>> mm;
        for(auto e:m)
        {
            mm.insert(make_pair(e.second,e.first));
        }
        for(auto e:mm)
        {
            if(k==0)
                break;
            v.push_back(e.second);
            k--;
        }
        return v;
    }
};